<template>
  <div class="home">
    <!-- 英雄区域 -->
    <section class="hero">
      <div class="container">
        <div class="hero-content fade-in">
          <h1 class="title-primary">优质货源，一站汇聚</h1>
          <p class="subtitle">连接优质鞋服商家，打造时尚供应链生态</p>
          <div class="hero-actions">
            <el-button type="primary" size="large" @click="$router.push('/merchants')">
              <el-icon><Shop /></el-icon>
              浏览商家
            </el-button>
            <el-button size="large" @click="$router.push('/contact')">
              <el-icon><Message /></el-icon>
              申请入驻
            </el-button>
          </div>
        </div>
      </div>
    </section>

    <!-- 特色服务 -->
    <section class="features section">
      <div class="container">
        <h2 class="title-secondary text-center">为什么选择我们</h2>
        <div class="features-grid">
          <div class="feature-card card">
            <div class="feature-icon">
              <el-icon size="48"><Star /></el-icon>
            </div>
            <h3>精选商家</h3>
            <p>严格筛选优质货源商家，确保产品品质和服务水准</p>
          </div>
          <div class="feature-card card">
            <div class="feature-icon">
              <el-icon size="48"><Lightning /></el-icon>
            </div>
            <h3>快速对接</h3>
            <p>高效的商家对接服务，快速建立合作关系</p>
          </div>
          <div class="feature-card card">
            <div class="feature-icon">
              <el-icon size="48"><Lock /></el-icon>
            </div>
            <h3>品质保障</h3>
            <p>完善的质量监控体系，为您的采购保驾护航</p>
          </div>
        </div>
      </div>
    </section>

    <!-- 精选商家 -->
    <section class="featured-merchants section">
      <div class="container">
        <h2 class="title-secondary text-center">精选商家</h2>
        <div class="merchants-grid">
          <div
            v-for="merchant in featuredMerchants"
            :key="merchant.id"
            class="merchant-card card"
            @click="$router.push(`/merchant/${merchant.id}`)"
          >
            <div class="merchant-image">
              <img :src="merchant.image" :alt="merchant.name" />
              <div class="merchant-category">{{ merchant.category }}</div>
            </div>
            <div class="merchant-info">
              <h3>{{ merchant.name }}</h3>
              <p>{{ merchant.description }}</p>
              <div class="merchant-meta">
                <span class="rating">
                  <el-icon><Star /></el-icon>
                  {{ merchant.rating }}
                </span>
                <span class="location">{{ merchant.location }}</span>
              </div>
            </div>
          </div>
        </div>
        <div class="text-center" style="margin-top: 40px;">
          <el-button type="primary" size="large" @click="$router.push('/merchants')">
            查看更多商家
          </el-button>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { Shop, Message, Star, Lightning, Lock } from '@element-plus/icons-vue'
import merchantsData from '../data/merchants.json'

interface Merchant {
  id: number
  name: string
  category: string
  description: string
  image: string
  rating: number
  location: string
  featured: boolean
}

const featuredMerchants = ref<Merchant[]>([])

onMounted(() => {
  // 获取精选商家（featured为true的商家）
  featuredMerchants.value = merchantsData.filter(merchant => merchant.featured).slice(0, 3)
})
</script>

<style scoped>
.home {
  min-height: 100vh;
}

/* 英雄区域 */
.hero {
  background: linear-gradient(135deg, #0071E3 0%, #005bb5 100%);
  color: white;
  padding: 120px 0;
  text-align: center;
}

.hero-content h1 {
  color: white;
  margin-bottom: 20px;
}

.hero-content .subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.25rem;
  margin-bottom: 40px;
}

.hero-actions {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

/* 特色服务 */
.features {
  background: white;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 40px;
  margin-top: 60px;
}

.feature-card {
  text-align: center;
  padding: 40px 30px;
}

.feature-icon {
  color: var(--primary-color);
  margin-bottom: 20px;
}

.feature-card h3 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 15px;
  color: var(--text-primary);
}

.feature-card p {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* 精选商家 */
.featured-merchants {
  background: var(--accent-color);
}

.merchants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 30px;
  margin-top: 60px;
}

.merchant-card {
  cursor: pointer;
  transition: all 0.3s ease;
}

.merchant-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.merchant-image {
  position: relative;
  height: 200px;
  overflow: hidden;
}

.merchant-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.merchant-card:hover .merchant-image img {
  transform: scale(1.05);
}

.merchant-category {
  position: absolute;
  top: 15px;
  right: 15px;
  background: var(--primary-color);
  color: white;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
}

.merchant-info {
  padding: 25px;
}

.merchant-info h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.merchant-info p {
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 15px;
}

.merchant-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rating {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #f39c12;
  font-weight: 500;
}

.location {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* 工具类 */
.text-center {
  text-align: center;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .hero {
    padding: 80px 0;
  }

  .hero-actions {
    flex-direction: column;
    align-items: center;
  }

  .features-grid {
    grid-template-columns: 1fr;
    gap: 30px;
  }

  .merchants-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}
</style>
